package cn.iocoder.yudao.module.product.sku.vo;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.api.product.sku.dto.AdminPriceRespDTO;
import cn.iocoder.yudao.module.api.product.sku.dto.ProductPropertyValueRespDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;

import static cn.iocoder.yudao.module.api.product.ConfigConstants.PROPERTY_NAME_DEFAULT;
import static cn.iocoder.yudao.module.api.product.ConfigConstants.PROPERTY_VALUE_NAME_DEFAULT;

@Schema(description = "管理后台 - 产品 SKU Response VO")
@Data
public class ProductSkuRespVO extends AdminPriceRespDTO {

    @Schema(description = "店铺编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "111")
    private Long shopId;

    @Schema(description = "产品 SKU 名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉小短袖")
    private String name;

    @Schema(description = "条形码", example = "15156165456")
    private String barCode;

    @Schema(description = "图片地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.example.com/xx.png")
    private String picUrl;

    @Schema(description = "库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "200")
    private Integer stock;

    @Schema(description = "产品重量,单位：kg 千克", example = "1.2")
    private Double weight;

    @Schema(description = "产品体积,单位：m^3 平米", example = "2.5")
    private Double volume;

    @Schema(description = "一级分销的佣金，单位：分", example = "199")
    @Deprecated
    private Integer firstBrokeragePrice;

    @Schema(description = "二级分销的佣金，单位：分", example = "19")
    @Deprecated
    private Integer secondBrokeragePrice;

    @Schema(description = "属性数组")
    private List<ProductPropertyValueRespDTO> properties;

    @Schema(description = "属性名称", example = "颜色+尺码")
    private String propertiesName;

    @SuppressWarnings("unused")
    public String getPropertiesName() {
        if (CollUtil.isEmpty(properties)) {
            return PROPERTY_NAME_DEFAULT;
        }
        return properties.stream().map(ProductPropertyValueRespDTO::getPropertyName).reduce((a, b) -> a + "+" + b).orElse(PROPERTY_NAME_DEFAULT);
    }

    @Schema(description = "属性名称", example = "卡其色+2XL")
    private String propertiesValue;

    @SuppressWarnings("unused")
    public String getPropertiesValue() {
        if (propertiesValue != null) {
            return propertiesValue;
        }
        return getProperties().stream()
                .map(ProductPropertyValueRespDTO::getValueName)
                .filter(it -> !PROPERTY_VALUE_NAME_DEFAULT.equals(it))
                .reduce((a, b) -> a + "+" + b)
                .orElse("");
    }

}
